<?php
include('../../../include/functions.inc.php');

if(getParam("op") == "cursos"){    
    $value = getParam("ID");
    $pieces = explode(" - ", $value);
    $id = $pieces[0];
    
    $cycle = getParam("CYCLE");

    $catAssign = $db->query_select("cllg_teacher_assign",sprintf("FK_TEACHER='%s' AND FK_CYCLE='%s'", $id, $cycle));

        if(count($catAssign) == 0){ 
            echo "<h5 style='color:blue'>No se encontraron asignaciones a este profesor</h5>";
        }else { ?>
            <table width="100%">
                <tr>
                    <th colspan="2">
                        <legend>Seleccione curso</legend>
                    </th>
                </tr>
                <tr>
                    <td width="10%">CURSO</td>
                    <td width="90%">
                        <select name="ASSIGN" style='width:400px'>
                            <option selected="selected" value="0">--Seleccione curso--</option>
                            <?php foreach($catAssign as $ass){
                                    $course = $db->query_select("cllg_courses_catalog",sprintf("CODE=%s", $ass['FK_COURSE']));
                                    $dias = "";
                                    if($ass['LUNES'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="LUNES";
                                    }
                                    if($ass['MARTES'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="MARTES";
                                    }
                                    if($ass['MIERCOLES'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="MIERCOLES";
                                    }
                                    if($ass['JUEVES'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="JUEVES";
                                    }
                                    if($ass['VIERNES'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="VIERNES";
                                    }
                                    if($ass['SABADO'] == 1){
                                        $dias = isEmpty($dias) ? $dias : "$dias, ";
                                        $dias.="SABADO";
                                    }
                                    ?>
                                    <option value="<?php echo $ass['ID']; ?>"><?php echo "[". $course[0]['CODE'] ."],".$course[0]['NAME']. " Seccion '". $ass['SECTION']."' Días ". $dias?></option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
            </table>
    <?php }
}elseif(getParam("op") == "name"){
    
    $value = getParam("ID");
    $pieces = explode(" - ", $value);
    $id = $pieces[0];
    $cat = $db->query_select("cllg_teacher",  sprintf("ID='%s'", $id));
    
        if(count($cat) == 0){ ?>
            <td colspan="2">
                <h5 style="color:blue">No se encontraron profesores con este ID</h5>
            </td>
    <?php }else{ ?>
            <td>
                NOMBRE:
            </td>
            <td>
                <input type="text" readonly="readonly" value="<?php echo $cat[0]['FIRST_NAME']." ".$cat[0]['LAST_NAME']; ?>" style="width:250px" name="NAME" id="NAME">
            </td>
    <?php }
}

